//
//  CQLogin.m
//  JDSideMenu
// (登录页)
//  Created by 常 琼 on 14-9-28.
//  Copyright (c) 2014年 Markus Emrich. All rights reserved.
//

#import "CQLogin.h"

#import "CQViewController.h"
#import "MBProgressHUD+MJ.h"

@interface CQLogin ()
//登录按钮
@property(nonatomic,weak) UIButton *login;
@property(nonatomic,weak) UITextField *text_phone;

@end

@implementation CQLogin


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor: [UIColor purpleColor]];
    
    
    
    //初始化 text 和登录button
    UITextField *textFile =  [[UITextField alloc] init];
    textFile.frame = CGRectMake(100, 100, 150, 50);
    UIButton *login =  [[UIButton alloc] initWithFrame:CGRectMake(100, 150, 40, 30)];

    [login setBackgroundColor:[UIColor redColor]];
    self.text_phone = textFile;
    self.login = login;
    
    //添加textfile
    //添加button
    [self.view addSubview:textFile];
    [self.view addSubview:login];
    
    //设置导航栏
    self.title = @"登录";
    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
    
    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(loginin)];
    
    
    [self.text_phone setBackgroundColor:[UIColor whiteColor]];
    
    
    
    //弹出第一响应者
    
    self.text_phone.keyboardType = UIKeyboardTypeNumberPad;
    [self.text_phone becomeFirstResponder];
    
    
}
/**
 *  点击登录按钮
 */
-(void)loginin
{
    NSLog(@"login login ");
    if ([self.text_phone .text isEqualToString:@"11"])//登录成功
    {
        //打开手势界面
         
        [self dismissViewControllerAnimated:YES completion:^{
            
           //提示登录成功
            [MBProgressHUD showSuccess:@"登录成功"];
            //发送通知给menu 顺便传过去一些信息
            NSNotificationCenter *center =  [NSNotificationCenter defaultCenter];
            NSDictionary *dic = @{@"key":self.text_phone.text};
            
            [center postNotificationName:@"LOGINED" object:self userInfo:dic];
            
            
        }];
    }
    else//登录失败
    {
     //弹出提示框
     //清空文本框
     [MBProgressHUD showError:@"登录失败"];
    }
    
}
/**
 *  点击关闭按钮
 */
-(void)close
{
    NSLog(@"close login");
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}


@end
